package com.gxa.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.pojo.Car;
import com.gxa.pojo.CarVO;
import com.gxa.service.CarService;
import com.gxa.utils.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
* @description: TODO
* @author JZ
* @date 2022/9/7 11:16
* @version 1.0
*/
@Api(tags = "车辆相关业务")
@RestController
@RequestMapping("car")
public class CarController {

    @Resource
    CarService service;
    ResponseData data;

    @PutMapping("/insert")
    @ApiOperation(value="增加车辆",httpMethod = "PUT",response = boolean.class)
    @ApiResponse(code = 200,message = "添加成功")
    @ResponseBody
    boolean insertCar(@RequestBody Car car){
        return service.insertCar(car);
    }
    @DeleteMapping("/delete")
    @ApiOperation(value="删除车辆",httpMethod = "DELETE",response = boolean.class)
    @ApiResponse(code = 200,message = "删除成功")
    @ResponseBody
    boolean deleteCar(int id){
        return service.deleteCar(id);
    }
    @ApiOperation(value="修改车辆",httpMethod = "PUT",response = boolean.class)
    @ApiResponse(code = 200,message = "修改成功")
    @ResponseBody
    @PutMapping("/update")
    boolean updateCar(Car car){
        return service.updateCar(car);
    }

    @ApiOperation(value="显示车辆",httpMethod = "POST",response = ResponseData.class)
    @ApiResponse(code = 200,message = "显示成功")
    @ResponseBody
    @PostMapping("/show")
    ResponseData selectVisitor(@ApiParam(name = "car",value = "车辆对象",required=true)@RequestBody CarVO car){
        PageHelper.startPage(Integer.parseInt(car.getPage()),Integer.parseInt(car.getLimit()));
        List<Car> cars = service.selectCar(car);
        PageInfo<Car> visitorPageInfo = new PageInfo<>(cars);
        ResponseData responseData = ResponseData.successData(cars);
        responseData.setCount((int) visitorPageInfo.getTotal());
        System.out.println(responseData);
        return responseData;
    }




}
